<template>
  <div class="test-result">
    <header class="header">
      <h1>{{ testResule.name }}</h1>
      <div class="grade-box">
        <span>总分：{{ testResule.full_score }}</span>
        <span>得分：{{ testResule.grade }}</span>
        <span
          >用时：{{ parseInt(testResule.spend_time / 60) + 1 || 0 }}分钟</span
        >
      </div>
    </header>
    <main>
      <div v-for="(problem, i) in testResule.items" :key="i">
        <!-- 题目 -->
        <p>
          {{ i + 1 }}、{{ problem.detail }}
          <span :class="[problem.is_right ? 'success' : 'error']"
            >本题得分： ({{ problem.score }}分)</span
          >
        </p>
        <!-- 选项 -->
        <div :class="['choice', problem.submit_answer == 1 ? 'choiced' : '']">
          A.{{ problem.a_option }}
        </div>
        <div :class="['choice', problem.submit_answer == 2 ? 'choiced' : '']">
          B.{{ problem.b_option }}
        </div>
        <div :class="['choice', problem.submit_answer == 3 ? 'choiced' : '']">
          C.{{ problem.c_option }}
        </div>
        <div :class="['choice', problem.submit_answer == 4 ? 'choiced' : '']">
          D.{{ problem.d_option }}
        </div>
        <!-- 正确答案 -->
        <div class="success top">
          正确答案：{{
            problem.answer == 1
              ? "A"
              : problem.answer == 2
              ? "B"
              : problem.answer == 3
              ? "C"
              : "D"
          }}
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { finishedExamPaperData } from "@/api/exam-paper";
export default {
  data() {
    return {
      testResule: {}
    };
  },
  created() {
    console.log(this.$route.query.id);
    finishedExamPaperData({ id: this.$route.query.id }).then(res => {
      console.log(res);
      this.testResule = res.data;
    });
  },
  methods: {},
  computed: {}
};
</script>

<style lang="scss" scoped>
.test-result {
  width: 960px;
  margin: 0 auto;
  .header {
    display: flex;
    flex-direction: column;
    align-items: center;
    .grade-box {
      width: 300px;
      display: flex;
      justify-content: space-between;
    }
  }
}
.choice {
  display: flex;
  align-items: center;
  margin: 4px 0;
  position: relative;
  &::before {
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    border: 2px solid #ccc;
    border-radius: 50%;
    margin-right: 10px;
  }
}
.choiced {
  color: #409eff;
  &::before {
    border-color: #409eff;
  }
  &::after {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #409eff;

    position: absolute;
    left: 6px;
    top: 6px;
  }
}
.error {
  color: #f56c6c;
}
.success {
  color: #67c23a;
}
.top {
  margin-top: 20px;
}
</style>
